from django.shortcuts import render
from rest_framework_extensions.cache.mixins import CacheResponseMixin
# Create your views here.
from rest_framework.viewsets import ReadOnlyModelViewSet

from areas.models import Area
from areas.serializers import AreaSerializer, SubAreaSerializer


class AreasViewSet(CacheResponseMixin,ReadOnlyModelViewSet):
    pagination_class=None

    def get_serializer_class(self):
    # def get_serializer(self, *args, **kwargs):
        if self.action=='list':
            return AreaSerializer
        else:
            return SubAreaSerializer
    def get_queryset(self):
        if self.action=='list':
            return Area.objects.filter(parent_id=None)
        else:
            return Area.objects.all()